// 引入样式
require("../../assets/css/index.less")
require("./login.less")
require('weui')

const { ready, getEle, addEvent } = require('../../utils/dom')
const { post } = require('../../utils/https')
const weui = require("weui.js")
const { set } = require('../../utils/local')

ready(() => {
    addEvent("#loginBtn", () => {
        if (getEle("#account").value && getEle("#password").value) {
            post('/api/user/login',
                {
                    account: getEle("#account").value,
                    password: getEle("#password").value
                }, res => {
                    if (res.errno == 0) {
                        set('token', res.data.token)
                        weui.toast('登录成功!', () => location.href = 'home.html')
                    } else {
                        weui.alert(res.message)
                    }

                })

        } else {
            getEle("#errMsg").textContent = '请输入用户账号/密码'
        }


    })

    addEvent("#getPwd", () => location.href = 'getPassword.html')
})
